<script setup>

// 1. 子组件定义属性接收父组件传值
const props = defineProps({
  money: {
    type: Number,
    default: 100
  },
  car: {
    type: String,
    required: true
  }
})

// console.log(props.money, props.car)

// 2. 子组件要通过自定义事件向父组件传值
const emit = defineEmits(['changeMoney', 'changeCar'])

const changeParentMoney = (money) => {
  // console.log(money)
  emit('changeMoney', money)
}


</script>

<template>
  <div>
    <h4>我是子组件</h4>
    <p>钱: {{ money }}, 车: {{ car }}</p>
    <button @click="changeParentMoney(100)">花了100块</button>
    <button @click="emit('changeCar', '宝马X3')">换一辆车</button>
  </div>
</template>

<style scoped></style>
